package com.cslg.ac.demo.dao.pet;


import com.cslg.ac.demo.util.integer.IntegerUtil;
import org.apache.catalina.LifecycleState;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.SplittableRandom;

@Mapper
public interface UserPetDAO {

    String TABLE_NAME = "r_user_pet";

    @Insert({"insert into ", TABLE_NAME, "(user_id, pet_type) values(#{userId}, #{petType})"})
    void insert(@Param("userId")int userId,@Param("petType")int petType);

    @Delete({"delete from ", TABLE_NAME, "where pet_id = #{petId}"})
    void delete(@Param("petId")int petId);

    @Select({"select pet_id petId from ", TABLE_NAME, "where user_id = #{userId} and pet_type = #{petType} limit #{offset}, #{num}"})
    Integer[] selectByUserId(@Param("userId")int userId, @Param("petType")int petType, @Param("offset") int offset, @Param("num") int num);

    @Select({"select pet_id petId from ", TABLE_NAME, "where user_id = #{userId} and pet_type = #{petType}"})
    List<Integer> selectByUserIdAndType(@Param("userId")int userId, @Param("petType")int petType);

    @Select({"select user_id userId from ", TABLE_NAME, "where pet_id = #{petId}"})
    Integer selectUserByPet(@Param("petId")int petId);

    @Select({"select user_id userId from ", TABLE_NAME, "where pet_type = #{petType}"})
    List<Integer> selectUserByPetType(@Param("petType")int petType);

    @Select({"select a.pet_id from ", TABLE_NAME, "a, e_t_account_info b, e_p_account_info c, e_pet_common d where ( a.user_id = b.id and " +
            "b.address like concat(concat('%',#{address}),'%')) or ( a.user_id = c.id and c.city like concat(concat('%',#{address}),'%')) and d.kind = #{kind} and d.id = a.pet_id order by a.pet_id desc limit #{offset}, #{num}"})
    List<Integer> selectByAddress(@Param("address")String address, @Param("kind")int kind ,@Param("offset")int offset, @Param("num")int num);

    @Select({"select a.pet_id from ", TABLE_NAME, "a, e_t_account_info b, e_p_account_info c, e_pet_common d where( ( a.user_id = b.id and " +
            "b.address like concat(concat('%',#{address}),'%')) or ( a.user_id = c.id and c.city like concat(concat('%',#{address}),'%'))) and d.kind = #{kind} and d.id = a.pet_id and d.gender = #{gender}" +
            "  order by a.pet_id desc limit #{offset}, #{num}"})
    List<Integer> selectByAddressAndGender(@Param("address")String address, @Param("kind")int kind , @Param("gender")int gender,@Param("offset")int offset, @Param("num")int num);

    @Select({"select a.pet_id from ", TABLE_NAME, "a, e_t_account_info b, e_p_account_info c, e_pet_common d where( ( a.user_id = b.id and " +
            "b.address like concat(concat('%',#{address}),'%')) or ( a.user_id = c.id and c.city like concat(concat('%',#{address}),'%'))) and d.kind = #{kind} and d.id = a.pet_id and d.gender = #{gender}" +
            " and d.type = #{type} order by a.pet_id desc  limit #{offset}, #{num}"})
    List<Integer> selectByAddressAndGenderAndType(@Param("address")String address, @Param("kind")int kind , @Param("gender")int gender, @Param("type")String type, @Param("offset")int offset, @Param("num")int num);

    @Select({"select a.pet_id from ", TABLE_NAME, "a, e_t_account_info b, e_p_account_info c, e_pet_common d where( ( a.user_id = b.id and " +
            "b.address like concat(concat('%',#{address}),'%')) or ( a.user_id = c.id and c.city like concat(concat('%',#{address}),'%'))) and d.kind = #{kind} and d.id = a.pet_id and d.type = #{type}" +
            " order by a.pet_id desc limit #{offset}, #{num}"})
    List<Integer> selectByAddressAndType(@Param("address")String address, @Param("kind")int kind , @Param("type")String type,@Param("offset")int offset, @Param("num")int num);

}
